package com.wsj.dao.hibernate;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wsj.dao.ITopTitleDao;
import com.wsj.web.vo.homeSite.Toptitle;

public class ToptitleDaoImpl extends HibernateDaoSupport implements ITopTitleDao {

	private JdbcTemplate jdbcTemplate;
	
	
	public void delete(Integer id) throws DataAccessException {
		String sql = " delete from toptitle where id = " + id;
		this.jdbcTemplate.execute(sql);
	}

	@SuppressWarnings("unchecked")
	public List<Toptitle> getAllList() throws DataAccessException {
		List<Toptitle> list = null;
		list = this.getHibernateTemplate().loadAll(Toptitle.class);
		if(list != null && list.size()>0){
			return list;
		}
		
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<Toptitle> getTopList(Integer top) throws DataAccessException {
		String sql = "from Toptitle as t where t.isDel = 0 and t.audite = 1 order by t.deliverDatetime desc ";
		List<Toptitle> list = this.getSession().createQuery(sql).setMaxResults(top).list();
		if(list != null && list.size()>0){
			return list;
		}
		return null;
	}

	public Toptitle loadById(Integer id) throws DataAccessException {
		Object obj = null;
		Toptitle t = new Toptitle();
		obj = this.getHibernateTemplate().get(Toptitle.class, id);
		if(obj != null){
			t = (Toptitle)obj;
		}
		return t;
	}

	public void saveOrUpdate(Toptitle topTitle) throws DataAccessException {
		this.getHibernateTemplate().saveOrUpdate(topTitle);
	}
	

	
	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}


}
